package com.bolang.onlycode.demo.aop;

import com.bolang.onlycode.demo.annoation.MyFirstAnnotation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class AfterAdviceAspect {
    @Pointcut("@annotation(com.bolang.onlycode.demo.annoation.MyFirstAnnotation)")
    public void logPointCut() {

    }
    @Around("logPointCut()")
    public void  aroundAdviceTest(ProceedingJoinPoint point) throws Throwable {
        MethodSignature signature = (MethodSignature) point.getSignature();
        Method method = signature.getMethod();
        Object[] args = point.getArgs();
        String type =null;
        MyFirstAnnotation syslog = method.getAnnotation(MyFirstAnnotation.class);
        if(syslog!=null){
           switch (syslog.operateType()){
               case 1 :type="查询";
                   break;
               case 2 :type="修改";
                   break;
               case 3 :type="增加";
                   break;
               case 4 :type="删除";
                   break;
               default:type="未知";
           }

        }
        for (Object arg : args) {
            System.out.println(type+method.getName()+arg);
        }
        //执行方法
        Object result = point.proceed();
    }
}
